<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/include/header.jsp"%>
<title>查询${config.beanDescription}列表</title>
</head>
<body>
	<div class="wrap">
		<%@ include file="/include/top.jsp"%>

		<div class="main">
			<%@ include file="/include/left.jsp"%>

			<div class="m_right">
				<div class="p_bar">您当前的位置：${config.beanDescription}管理 >> 列表</div>
				<div class="con_box" id="queryDiv">
				 	<input type="hidden" id="CSRFToken" name="CSRFToken" value="<hna:csrfToken />" />
					<!-- 查询条件 : 注意加上 data-qname -->
					<table class="c_table m_t10">
						<tr>
							<td> :</td>
							<td align="left"><input type="text" data-qname="code" class="input_txt" /></td>
							<td class="t_r">
								<button class="c_btn" id="searchBtn">查询</button>
								<button class="a_btn" id="addBtn">新增</button>
							</td>
						</tr>
					</table>					
				</div>
				<table id="tbwrap" class="table_list"></table>
				<div class="page eui-pager-custom" id="j_pager"></div>
			</div>
		</div>
		<div class="bottom_box"></div>
	</div>

	<script type="text/html" id="tb_template">
		<thead>
				<tr>
<#list columnList as column>
					<th>${column.dbColumnComment}</th>
</#list>
					<th>操作</th>
				</tr>
		</thead>
		<tbody data-type="body">
			<!if(list.length>0) { !>
				<!for(var i=0,len=list.length;i<len;i++){
					var item = list[i],classItem = (i%2!=0)?"odd td_odd":"even";
				!>
				<tr class="gradeA <!=classItem!>">
					<#list columnList as column>
						<td title="<!=item["${column.javaPropertyName}"]!>"><!=item["${column.javaPropertyName}"]!></td>
					</#list>
						<td>
							<a title="详情" data-value="<!=item["${columnList[0].javaPropertyName}"]!>" action="view">详情</a>&nbsp;
							<a title="修改" data-value="<!=item["${columnList[0].javaPropertyName}"]!>" action="edit">修改</a> &nbsp;
							<a title="删除" data-value="<!=item["${columnList[0].javaPropertyName}"]!>" action="delete">删除</a>&nbsp;							
						</td>
				</tr>
			<!}!>
			<!}else{!>
				<tr>
					<td colspan="${columnList?size+1}"> 暂无数据</td>
				</tr>
			<!}!>
		</tbody>
	</script>
	<script type="text/javascript">
		var ${simpleBeanName}Dialog;
		$(function() {

			//ajax请求添加等待图片
			$(document).ajaxStart(function() {
				ZENG.msgbox.show(" 正在加载中，请稍后...", 6, 8000);
			});

			$(document).ajaxComplete(function() {
				ZENG.msgbox.hide();
			});

			// 添加
			$("#addBtn").click(function() {
				seajs.use("component/dialog", function(dialog) {
					${simpleBeanName}Dialog = new dialog({
						"width": 800,
						"height": 500,
						"contentType": "iframe",
						"contentScroll": false,
						"html": "${ctx}/${simpleBeanName}/toAdd.do",
						"title": "添加${config.beanDescription}信息" //标题
					});
				});
			});
			
			// 详细
			$("#tbwrap").delegate("[action='view']", "click", function() {
				//获取主键
				var ${beanId} = $(this).data("value");
				// 弹窗窗口
				seajs.use("component/dialog", function(dialog) {
					${simpleBeanName}Dialog = new dialog({
						"width" : 800,
						"height" : 600,
						"contentType" : "iframe",
						"contentScroll": false,
						"html" : "${ctx}/${simpleBeanName}/view.do?${beanId}=" + ${beanId}, // 内容
						"title" : "查看${config.beanDescription}详细信息" //标题
					});
				});
			});
			
			// 编辑
			$("#tbwrap").delegate("[action='edit']", "click", function() {
				//获取主键
				var ${beanId} = $(this).data("value");
				//弹窗窗口
				seajs.use("component/dialog", function(dialog) {
					${simpleBeanName}Dialog = new dialog({
						"width": 800,
						"height": 600,
						"contentType": "iframe",
						"contentScroll": false,
						"html": "${ctx}/${simpleBeanName}/toEdit.do?${beanId}=" + ${beanId},
						"title": "编辑${config.beanDescription}详细信息" //标题
					});
				});
			});
			
			// 删除
			$("#tbwrap").delegate("[action='delete']", "click", function() {
				var ${beanId} = $(this).data("value");
				if (confirm('确定删除？')) {
					commonUtils.postAjax("${ctx}/${simpleBeanName}/delete.do", {${beanId} :${beanId},CSRFToken : $("#CSRFToken").val()}, function(result){
						if (999 == result.code) {
							alert(result.msg);
						}
						if (200 == result.code) {
					        alert("操作成功");
					        search();
						}
					});
				}
							
			});
			// 5、查询
			$("#searchBtn").click(function() {
				search();
			});
			
			// 页面加载完成调用查询分页
			search();
		});
	</script>

<script type="text/javascript">
		function search() {
			var paramData = pageUtils.getQueryDivDefault("queryDiv");
			seajs.use([ "component/table" ], function(uiTable) {
				var param = {
					url : "${ctx}/${simpleBeanName}/ajaxPage.do",
					data : paramData
				};
				pageUtils.getData(param, function(result) {
					pageUtils.buildTable(result, param, uiTable);
				});
			});
		}
	</script>
	<%@ include file="/include/footer.jsp"%>
</body>
</html>